package com.estore.model;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.HashMap;
import java.util.Objects;

public class OrderRecord implements Serializable {
    private static final long serialVersionUID = 1L;

    private final String orderId;
    private final Map<String, Integer> items; // productId -> quantity
    private final double totalAmount;
    private final LocalDateTime orderTime;

    public OrderRecord(String orderId, Map<String, Integer> items, double totalAmount) {
        this.orderId = Objects.requireNonNull(orderId, "Order ID cannot be null");
        this.items = new HashMap<>(Objects.requireNonNull(items, "Items cannot be null"));
        this.totalAmount = totalAmount;
        this.orderTime = LocalDateTime.now();
    }

    // Getters
    public String getOrderId() {
        return orderId;
    }

    public Map<String, Integer> getItems() {
        return new HashMap<>(items);
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public LocalDateTime getOrderTime() {
        return orderTime;
    }

    @Override
    public String toString() {
        return String.format("Order[ID=%s, Time=%s, Amount=%.2f, Items=%d]",
                orderId, orderTime, totalAmount, items.size());
    }
}
